import random
class users:
    def __init__(self,account,user_name,password,address,money,bank):
        self.account = account
        self.username = user_name
        self.password = password
        self.address = address
        self.money = money
        self.bank = bank

#用户表
user_list = [
    {"账号":"12345678","姓名":"张三","密码":12345678,"地址":"北京市朝阳区","余额":5000,"开户行":"中国工商银行昌平支行"},
    {"账号":"12345679","姓名":"张四","密码":12345678,"地址":"北京市朝阳区","余额":3000,"开户行":"中国工商银行昌平支行"}

]
#开户
def open(acc):
    username = input("姓名")
    password = input("密码")
    address = input("地址")
    money = input("余额")
    # account = random.randint(10000000,99999999)
    account = acc
    print(account)
    bank = "中国工商银行昌平支行"
    user = {}
    user.update({"账号":account,"姓名":username,"密码":password,"地址":address,"余额":money,"开户行":bank})
    user_list.append(user)
    # print(user)
    return user
# open()
#存钱
def save(acc,money):
    a=False
    for i in user_list:
        if i["账号"] == acc:
            i["余额"]=int(i["余额"])+money
            a = True
            print("余额：",i["余额"])
            break
    return a
# print(save("12345678",500))
# print()

#取钱
def getmoney(acc,password,money):
    a = 1
    for i in user_list:
        if i["账号"] == acc:
            if i["密码"]==password:
                if i["余额"]>=money:
                    i["余额"] = int(i["余额"]) - money
                    a = 0
                    print("余额：", i["余额"])
                    break
                else:a = 3
                break
            else:a = 2
            break
    return a




#转账
def movemoney(acc1,acc2,password,money):
    a = 1
    cou=0
    for i in user_list:
        if i["账号"] == acc1:
            u1 = i
            cou = cou+1
            break
    for i in user_list:
        if i["账号"] == acc2:
            u2 = i
            cou = cou + 1
            break
    if cou == 2:
        if u1["密码"]==password:
            if u1["余额"]>=money:
                u1["余额"] = int(u1["余额"]) - money
                u2["余额"] = int(u2["余额"]) + money
                a = 0
                print("转出账户余额：", u1["余额"])
                print("转入账户余额：", u2["余额"])
            else:a = 3
        else:a = 2
    else:a = 1
    return a
# a=getmoney("12345678",12345678,50000)
# print(a)
# movemoney("12345678","12345679",12345678,200)
#查询
def select(acc1,password):
    for i in user_list:
        if i["账号"] == acc1:
            if i["密码"]==password:
                print(f"当前账号：{i['账号']},密码:{i['密码']},余额：{i['余额']}元，用户居住地址：{i['地址']}，当前账户的开户行：{i['开户行']}")
                break
            else:print("密码错误")
        else:print("用户不存在")
    return
while True:
    print("*******************************")
    print("*          中国工商银行         *")
    print("*******************************")
    print("* 1.开户                       *")
    print("* 2.存钱                       *")
    print("* 3.取钱                       *")
    print("* 4.转账                       *")
    print("* 5.查询                       *")
    print("* 6.退出                       *")
    print("*******************************")
    print()
    choose = int(input("输入序号："))
    if choose == 1:
        p = -1
        acc = random.randint(10000000, 99999999)
        # acc = 12345678
        for i in user_list:
            if i["账号"] == acc:
                print(i["账号"])
                p = 2
                break
        if len(user_list)<100 and p !=2:
            p = 1
            massage = open(acc)
        else:p = 3
        if p==1:
            print("开户成功")
            print(massage)
        elif p ==2:
            print("账号已存在")
        else:print("用户库已满")
    elif choose == 2:
        acc = input("输入存钱账号：")
        money = int(input("输入存钱金额："))
        mass = save(acc, money)
        if mass ==  True:
            print("存钱成功")
        else:print("账户不存在")
    elif choose == 3:
        acc = input("输入取钱账号：")
        password = int(input("输入密码"))
        money = int(input("输入取钱金额："))
        a = getmoney(acc, password, money)
        # print(a)
        if a == 0:
            print("取钱成功")
        elif a==1:
            print("账号不存在")
        elif a==2:
            print("密码不对")
        else:
            print("钱不够")
    elif choose == 4:
        acc1 = input("输出转出账号：")
        acc2 = input("输入转出账号：")
        password = int(input("输入密码"))
        money = int(input("输入转账金额："))
        a = movemoney(acc1,acc2,password,money)
        # print(a)
        if a == 0:
            print("转账成功")
        elif a == 1:
            print("账号不存在")
        elif a == 2:
            print("密码不对")
        else:
            print("钱不够")
    elif choose == 5:
        acc = input("查询账号：")
        password = int(input("输入密码"))
        select(acc,password)
    elif choose == 6:
        print("biebie")
        break
    else:print("非法")



